/**
 * 
 */
package com.ydy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ydy.annotation.CheckFormRepeat;
import com.ydy.annotation.CtrlParam;
import com.ydy.annotation.StaffToken;
import com.ydy.controller.base.BaseController;
import com.ydy.model.RestRecord;
import com.ydy.service.restRecord.RestRecordService;
import com.ydy.utils.StringUtils;
import com.ydy.vo.other.BaseVo;
import com.ydy.vo.other.PageVo;

/**
 * @author xuzhaojie
 *
 *         2019年1月18日 上午9:17:29
 */
@Controller
@RequestMapping(value = "restRecord", name = "店铺休息记录模块")
public class RestRecordController extends BaseController {

	@Autowired
	private RestRecordService restRecordService;

	@StaffToken
	@GetMapping(value = "select", name = "店员查看店铺休息记录")
	@ResponseBody
	public ResponseEntity<PageVo<RestRecord>> select(RestRecord restRecord, Integer page, Integer size) {
		StringUtils.setParamEmptyToNull(restRecord);
		restRecord.setShopId(getStaff().getShopId());
		PageVo<RestRecord> vo = restRecordService.select(restRecord, page, size);
		return ResponseEntity.ok(vo);
	}

	@StaffToken
	@CheckFormRepeat
	@PostMapping(value = "save", name = "店员保存店铺休息记录")
	@ResponseBody
	public ResponseEntity<RestRecord> save(RestRecord restRecord) {
		restRecord.setShopId(getStaff().getShopId());
		return ResponseEntity.ok(restRecordService.saveOrUpdate(restRecord));
	}

	@StaffToken
	@CheckFormRepeat
	@DeleteMapping(value = "delete", name = "店员删除店铺休息记录")
	@ResponseBody
	public ResponseEntity<BaseVo> delete(@CtrlParam("id") Long id) {
		return ResponseEntity.ok(restRecordService.delete(id, getStaff()));
	}

	@StaffToken
	@GetMapping(value = "selectById", name = "店员查看店铺休息记录详情")
	@ResponseBody
	public ResponseEntity<RestRecord> selectById(@CtrlParam("id") Long id) {
		return ResponseEntity.ok(restRecordService.selectById(id, getStaff()));
	}
}